/*
Farmer Duel beneath an Active Volcano
(c) Rachel J. Morris, 2011
June - July 2011 project
http://www.moosader.com/

Farmer Duel - GNU GPL v3
Sader - MIT
*/

#include "StateMenu.h"

StateMenu::StateMenu()
{
    m_code = MENU;
}

void StateMenu::Init()
{
    LoadAssets();

    titleScreen.Init( TITLESCREEN );
    titleScreen.SetTexture( m_textureMgr.GetAsset( "titlescreen" ) );

    input.PopulateActionList( m_code );
}

void StateMenu::LoadAssets()
{
    std::vector<std::string> textureAssets;
    textureAssets.push_back( "titlescreen.jpg" );
    m_textureMgr.LoadAssets( textureAssets );
}

int StateMenu::MainLoop()
{
    input.ResetInputCooldown();
    closeState = false;

    input.SetWindow( app );

    while ( !closeState )
    {
        app->GetEvent();
        actions = input.Actions();

        if ( actions[ STATE_EXIT ] ) { return EXIT; }
        if ( actions[ STATE_GAME ] ) { return GAME; }

        input.Update();

        // Draw
        Render();
    }

    return EXIT;
}

void StateMenu::Render()
{
    app->window.SetActive();
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    glTranslatef( -1024/2, -768/2, -520 );

    titleScreen.Draw( sader::XY );

    app->window.Display();
}
